iT邦幫忙

2025 iThome 鐵人賽

DAY 5
0
Security

走進資安現場: JavaScript資安逆向工程超實戰系列 第 5

Day 5 逆向實戰 - 模擬請求計算總和 (簡單)

  • 分享至 

  • xImage
  •  

https://ithelp.ithome.com.tw/upload/images/20250904/201697751dWtBp0x1o.jpg

本系列文章所討論的 JavaScript 資安與逆向工程技術,旨在分享知識、探討防禦之道,並促進技術交流。
所有內容僅供學術研究與學習,請勿用於任何非法或不道德的行為。
讀者應對自己的行為負完全責任。尊重法律與道德規範是所有技術人員應共同遵守的準則。

本文同步發佈:https://nicklabs.cc/javascript-reverse-engineering-sum

挑戰網址

aHR0cHM6Ly93d3cubWFzaGFuZ3BhLmNvbS9wcm9ibGVtLWRldGFpbC8xLw==

解題過程

開啟 Network 並翻頁查看請求

可以一次翻兩頁查看兩次請求的Headers 及 UrlParams 或 PostData(若有),有沒有類似隨機變化的數值。

https://ithelp.ithome.com.tw/upload/images/20250904/20169775NEKPaEwh4P.jpg

這兩個請求的Method為GET,所以沒有PostData需要檢查。

https://ithelp.ithome.com.tw/upload/images/20250904/20169775zmT9yy9ZWs.jpg

從這兩個請求的Headers中查看到的都是固定的參數,故猜測沒有任何的防護。

直接模擬請求看看是否能成功取得資料。

取得請求的 Node.js Fetch程式碼

在要複製的請求上點右鍵 Copy > Copy as fetch (Node.js) 即可得到程式碼

fetch("https://xxxxxxxxxx/api/problem-detail/1/data/?page=2", {
  "headers": {
    "accept": "*/*",
    "accept-language": "zh-TW,zh;q=0.9,en;q=0.8,en-US;q=0.7",
    "cache-control": "no-cache",
    "pragma": "no-cache",
    "priority": "u=1, i",
    "sec-ch-ua": "\"Not;A=Brand\";v=\"99\", \"Google Chrome\";v=\"139\", \"Chromium\";v=\"139\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"macOS\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "cookie": "sessionid=xxxxxxxxxx",
    "Referer": "https://xxxxxxxxxx/problem-detail/1/"
  },
  "body": null,
  "method": "GET"
});

複製的程式碼沒有user-agent需要手動加上

"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36",

完整程式碼

經過測試可以取得資料,所以我們將程式碼完善一下讓他抓滿20頁並計算總和即可得到挑戰題的答案。

const getPage = async(page) => {
    console.log(`run page: ${page}`)

    const response = await fetch(`https://xxxxxxxxxx/api/problem-detail/1/data/?page=${page}`, {
        "headers": {
            "accept": "*/*",
            "accept-language": "zh-TW,zh;q=0.9,en;q=0.8,en-US;q=0.7",
            "cache-control": "no-cache",
            "pragma": "no-cache",
            "priority": "u=1, i",
            "sec-ch-ua": "\"Not;A=Brand\";v=\"99\", \"Google Chrome\";v=\"139\", \"Chromium\";v=\"139\"",
            "sec-ch-ua-mobile": "?0",
            "sec-ch-ua-platform": "\"macOS\"",
            "sec-fetch-dest": "empty",
            "sec-fetch-mode": "cors",
            "sec-fetch-site": "same-origin",
            "cookie": "sessionid=xxxxxxxxxx",
            "Referer": "https://xxxxxxxxxx/problem-detail/1/",
            "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36",
        },
        "body": null,
        "method": "GET"
    });

    let json = await response.json()

    return json.current_array.reduce((a, b) => a + b, 0);
}

(async() => {
    let total = 0;
    for(let i = 1; i <= 20; i++){
        total += (await getPage(i))
    }

    console.log(`total: ${total}`)
})()

使用Node執行JS程式

https://ithelp.ithome.com.tw/upload/images/20250904/20169775gSPBxuBCIS.jpg

順利取得20頁的資訊並進行加總。

一個沒有任何防護的API,就相當於把資料裸露在網路上。

攻擊者不需要高深的技術,只要會改參數與模擬請求,就能惡意取得資料。


上一篇
Day 4 使用 NodeJS 模擬發送 Network 攔截的請求
下一篇
Day 6 DevTools debugger 常見觸發方式與解法
系列文
走進資安現場: JavaScript資安逆向工程超實戰7
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言